package com.iscas.tech.controller;

import com.iscas.tech.entity.AtExperts;
import com.iscas.tech.param.PageParam;
import com.iscas.tech.service.AtExpertsService;
import com.iscas.tech.utils.ResponseUtil;
import com.iscas.tech.vo.MdWithExpert;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.shiro.util.LoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 专家信息表 控制器
 *
 * @author yangyi
 * @since 2020-10-26
 */
@Slf4j
@RestController
@RequestMapping("/expert")
@Api(value = "专家信息表API", tags = {"专家信息表"})
public class AtExpertsController extends BaseController {

    @Autowired
    private AtExpertsService atExpertsService;

    /**
     * 添加专家信息表
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加专家信息表", response = ApiResult.class)
    public ApiResult<Boolean> addAtExperts(@RequestBody MdWithExpert param) throws Exception {
        if (LoginUtil.getUserId() == null) {
            return ApiResult.fail(ApiCode.UNAUTHORIZED);
        }
        param.setCreateTitle(LoginUtil.getUserId().intValue());
        return ApiResult.result(atExpertsService.saveAtExperts(param));
    }

    /**
     * 修改专家信息表
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改专家信息表", response = ApiResult.class)
    public ApiResult<Boolean> updateAtExperts(@RequestBody MdWithExpert param) throws Exception {
        return ApiResult.result(atExpertsService.updateAtExperts(param));
    }

    /**
     * @param ids    待删除的专家/科技人才主键ID字符串，以","分隔
     * @param mdType 所属功能{@link com.iscas.tech.bo.MdType}
     * @return 删除专家/科技人才信息
     * @throws Exception 删除异常
     */
    @RequestMapping(value = "delete", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "删除专家信息表", response = ApiResult.class)
    public ApiResult<Boolean> deleteAtExperts(String ids, Integer mdType) throws Exception {
        return ApiResult.result(atExpertsService.deleteExperts(ids, mdType));
    }

    /**
     * @param id 专家/科技人才主键ID
     * @throws Exception 查询异常
     */
    @RequestMapping(value = "info", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "获取专家/科技人才信息", response = AtExperts.class)
    public void getExpert(Long id) throws Exception {
        ResponseUtil.write(getResponse(), ApiResult.ok(atExpertsService.get(id)));
    }

    /**
     * @param pageParam  分页参数
     * @param expertType 人员类型{@link com.iscas.tech.bo.ExpertType}
     * @param audit      审核状态（0-未审核 | 1-已审核）
     * @throws Exception 查询异常
     */
    @RequestMapping("/getPageList")
    @ApiOperation(value = "分页获取专家/科技人才列表", response = AtExperts.class)
    public void getExpertOrTalentPageList(PageParam pageParam, Integer expertType, Integer audit) throws Exception {
        ResponseUtil.write(getResponse(), ApiResult.ok(atExpertsService.getExpertOrTalentPageList(pageParam, expertType, audit)));
    }

    /**
     * @param id 专家/科技人才主键ID
     * @return 审核专家/科技人才信息（标记已通过）
     * @throws Exception 审核异常
     */
    @PostMapping("/check")
    @ApiModelProperty(value = "审核专家/科技人才信息（标记已通过）")
    public ApiResult<Boolean> checkExpertOrTalent(Long id) throws Exception {
        return ApiResult.result(atExpertsService.checkExpertOrTalent(id));
    }
}

